package com.yilong.springcloudalibabanacos.sys.controller;

import com.yilong.springcloudalibabanacos.sys.utils.MQProducerServiceUtil;
import org.apache.rocketmq.client.producer.SendResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @项目名称: com.yilong.springcloudalibabanacos.sys.controller
 * @类名称: RocketMQController
 * @类描述: #服务类
 * @功能描述: 功能描述
 * @创建人: WYL
 * @创建时间: 2022-12-17 20:46:03
 * @修改备注: 对该类进行修改时备注该处
 * @修改记录: 修改时间 修改人员 修改原因
 * -----------------------------------------------------
 * @Copyright (c) 宇信科技-版权所有
 */

@RestController
@RequestMapping("rocketmq")
public class RocketMQController {

    public static final Logger LOGGER = LoggerFactory.getLogger(RocketMQController.class);

    public static final String TOPIC_GROUP = "test-topic";

    @Autowired
    private MQProducerServiceUtil mqProducerServiceUtil;

    /**
     * 同步发送消息
     *
     * @param message
     */
    @RequestMapping("sendMsg")
    public SendResult sendMsg(String message) {
        return mqProducerServiceUtil.sendMsg(TOPIC_GROUP, message);
    }

    @RequestMapping("sendMsgTag")
    public SendResult sendMsgTag(String message, String tag) {
        return mqProducerServiceUtil.sendMsg(TOPIC_GROUP + ":" + tag, message);
    }

    @RequestMapping("syncSendOrderly")
    public List<SendResult> syncSendOrderly(String message) {
        List<SendResult> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            SendResult sendResult = mqProducerServiceUtil.syncSendOrderly("orderTopic", message + i, "syncSendOrderly");
            list.add(sendResult);
        }
        return list;
    }
}
